/**
 * Created by PanJiaChen on 16/11/18.
 */

/**
 * @param {string} path
 * @returns {Boolean}
 */
export function isExternal(path) {
  return /^(https?:|mailto:|tel:)/.test(path)
}

/**
 * @param {string} str
 * @returns {Boolean}
 */
export function validUsername(str) {
  const valid_map = ['admin', 'editor']
  return valid_map.indexOf(str.trim()) >= 0
}

/**
 * 时间格式化
 */
export function dateFormat(date) {
  let date_ = {}
  if (typeof date === 'number') {
    date = new Date(date)
  }
  date_ = {
    year: date.getFullYear().toString(),
    month: (date.getMonth() + 1).toString(),
    day: date.getDate().toString(),
    hour: date.getHours().toString(),
    minute: date.getMinutes().toString(),
    second: date.getSeconds().toString()
  }
  for (const i in date_) {
    if (date_[i].length === 1) {
      date_[i] = '0' + date_[i]
    }
  }
  return date_.year + '-' + date_.month + '-' + date_.day + ' ' + date_.hour + ':' + date_.minute + ':' + date_.second
}
